﻿using System.Globalization;
using EPiServer.Web.WebControls;

namespace OpenWaves.EPiServer.BrightcoveVideoCloudProperty
{
    public class VideoCloudProperty : Property
    {
        public const string UIHint = "ow-epi-videocloud";
        
        public int VideoHeight
        {
            get
            {
                return this.GetIntegerValue("VideoHeight");
            }
            set
            {
                this.RenderSettings.SetAttribute("VideoHeight", value.ToString(CultureInfo.InvariantCulture));
            }
        }

        public int VideoWidth
        {
            get
            {
                return this.GetIntegerValue("VideoWidth");
            }
            set
            {
                this.RenderSettings.SetAttribute("VideoWidth", value.ToString(CultureInfo.InvariantCulture));
            }
        }

        private int GetIntegerValue(string keyName)
        {
            int value;
            if (int.TryParse(this.RenderSettings.GetAttribute(keyName), NumberStyles.Integer,
                             CultureInfo.InvariantCulture, out value))
            {
                return value;
            }
            return 0;
        }
    }
}